/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on 1.3.2011, 11:31:42
 */
package jlibrarian.desktop;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import jlibrarian.BookManagerImpl;
import jlibrarian.CustomerManagerImpl;
import jlibrarian.DbManager;
import jlibrarian.JLibException;
import jlibrarian.RentManagerImpl;
import jlibrarian.entities.Book;
import jlibrarian.entities.Customer;
import jlibrarian.entities.Rent;
import jlibrarian.interfaces.BookManager;
import jlibrarian.interfaces.CustomerManager;
import jlibrarian.interfaces.RentManager;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author dandelion8
 */
public class MainFrame extends javax.swing.JFrame {

    /** WORKERS */
    class CustomersTableReloadWorker extends SwingWorker {

        @Override
        protected Object doInBackground() {
            CustomerManager cm = new CustomerManagerImpl(DbManager.getDataSource());
            //cm.getAllCustomers()

            String[] columns = {"cid", "firstName", "surname", "city", "street", "telephone"};
            String[] columnNames = MyBundle.getCustomersColumnNames();

            DefaultTableModel model = (DefaultTableModel) customersTable.getModel();

            if (model instanceof JLibrarianTableModel) {
                JLibrarianTableModel jmodel = (JLibrarianTableModel) model;

                jmodel.setColumnNames(columnNames);
                jmodel.setColumns(columns);
                jmodel.setDataFromCollection(cm.getAllCustomers());
            } else {
                throw new JLibException("Table model not valid.");

            }
            return null;
        }
    }

    class BooksTableReloadWorker extends SwingWorker {

        @Override
        protected Object doInBackground() {
            BookManager bm = new BookManagerImpl(DbManager.getDataSource());

            String[] columns = {"bid", "title", "authors", "quantity", "available", "note"};
            String[] columnNames = MyBundle.getBooksColumnNames();

            DefaultTableModel model = (DefaultTableModel) booksTable.getModel();

            if (model instanceof JLibrarianTableModel) {
                JLibrarianTableModel jmodel = (JLibrarianTableModel) model;

                jmodel.setColumnNames(columnNames);
                jmodel.setColumns(columns);

                String title = bookSearchTitleField.getText();
                String author = bookSearchAuthorField.getText();

                if (!title.equals("")) {
                    title = "%" + title + "%";
                } else {
                    title = null;
                }

                if (!author.equals("")) {
                    author = "%" + author + "%";
                } else {
                    author = null;
                }

                jmodel.setDataFromCollection(bm.getAllBooks());
            } else {
                throw new JLibException("Table model not valid.");
            }

            return null;
        }
    }

    class RentsTableReloadWorker extends SwingWorker {

        @Override
        protected Object doInBackground() {
            RentManager rm = new RentManagerImpl(DbManager.getDataSource());

            String[] columns = {"rid", "book", "customer", "borrowed", "toReturn", "returned"};
            String[] columnNames = MyBundle.getRentsColumnNames();

            DefaultTableModel model = (DefaultTableModel) rentsTable.getModel();

            if (model instanceof JLibrarianTableModel) {
                JLibrarianTableModel jmodel = (JLibrarianTableModel) model;

                jmodel.setColumnNames(columnNames);
                jmodel.setColumns(columns);

                jmodel.setDataFromCollection(rm.getAllRents(rentsArchiveToggleButton.isSelected()));
            } else {
                throw new JLibException("Table model not valid.");

            }

            return null;
        }
    }
    
    
    
    class SearchBooksWorker extends SwingWorker {

        @Override
        protected Object doInBackground() {
            BookManager bm = new BookManagerImpl(DbManager.getDataSource());



                String[] columns = {"bid", "title", "authors", "quantity", "available", "note"};
                String[] columnNames = MyBundle.getBooksColumnNames();

                DefaultTableModel model = (DefaultTableModel) booksTable.getModel();

                if (model instanceof JLibrarianTableModel) {
                    JLibrarianTableModel jmodel = (JLibrarianTableModel) model;

                    jmodel.setColumnNames(columnNames);
                    jmodel.setColumns(columns);

                    String title = bookSearchTitleField.getText();
                    String author = bookSearchAuthorField.getText();

                    if (title.equals("")) {
                        title = null;
                    }

                    if (author.equals("")) {
                        author = null;
                    }

                    jmodel.setDataFromCollection(bm.findBooksByAuthorAndTitle(author, title));
                } else {
                    throw new JLibException("Table model not valid.");
                }
             return null;
        }
    }
    
    class SearchCustomersWorker extends SwingWorker {

        @Override
        protected Object doInBackground() {
            CustomerManager cm = new CustomerManagerImpl(DbManager.getDataSource());
                String[] columns = {"cid", "firstName", "surname", "city", "street", "telephone"};
                String[] columnNames = MyBundle.getCustomersColumnNames();

                DefaultTableModel model = (DefaultTableModel) customersTable.getModel();

                if (model instanceof JLibrarianTableModel) {
                    JLibrarianTableModel jmodel = (JLibrarianTableModel) model;

                    jmodel.setColumnNames(columnNames);
                    jmodel.setColumns(columns);

                    String firstname = customerSearchFirstNameField.getText();
                    String surname = customerSearchSurnameField.getText();

                    if (firstname.equals("")) {
                        firstname = null;
                    }

                    if (surname.equals("")) {
                        surname = null;
                    }

                    jmodel.setDataFromCollection(cm.findCustomerByNames(firstname, surname));
                } else {
                    throw new JLibException("Table model not valid.");
                } 
            return null;
        }
    }
    
    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        aboutDialog = new javax.swing.JDialog();
        aboutDialogNameLabel = new javax.swing.JLabel();
        aboutDialogTextAuthors = new javax.swing.JLabel();
        aboutDialogClose = new javax.swing.JButton();
        aboutDialogTextLink = new javax.swing.JLabel();
        customerEditFrame = new javax.swing.JFrame();
        firstNameLabel = new javax.swing.JLabel();
        firstNameField = new javax.swing.JTextField();
        surnameLabel = new javax.swing.JLabel();
        surnameField = new javax.swing.JTextField();
        cityLabel = new javax.swing.JLabel();
        cityField = new javax.swing.JTextField();
        streetField = new javax.swing.JTextField();
        streetLabel = new javax.swing.JLabel();
        telephoneField = new javax.swing.JTextField();
        telephoneLabel = new javax.swing.JLabel();
        saveCustomerButton = new javax.swing.JButton();
        bookEditFrame = new javax.swing.JFrame();
        saveBookButton = new javax.swing.JButton();
        titleField = new javax.swing.JTextField();
        quantityField = new javax.swing.JTextField();
        quantityLabel = new javax.swing.JLabel();
        titleLabel = new javax.swing.JLabel();
        authorsLabel = new javax.swing.JLabel();
        authorsField = new javax.swing.JTextField();
        noteLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        noteField = new javax.swing.JTextArea();
        customersTablePopupMenu = new javax.swing.JPopupMenu();
        customersTablePopupMenuEditItem = new javax.swing.JMenuItem();
        customersTablePopupMenuDeleteItem = new javax.swing.JMenuItem();
        rentEditFrame = new javax.swing.JFrame();
        editRentCustomerLabel = new javax.swing.JLabel();
        editRentBookLabel = new javax.swing.JLabel();
        saveRentButton = new javax.swing.JButton();
        editRentBorrowedLabel = new javax.swing.JLabel();
        editRentToBeReturnedLabel = new javax.swing.JLabel();
        editRentCustomerSearchField = new javax.swing.JTextField();
        editRentCustomerSearchButton = new javax.swing.JButton();
        editRentBookSearchField = new javax.swing.JTextField();
        editRentBookSearchButton = new javax.swing.JButton();
        editRentBorrowedField = new com.toedter.calendar.JDateChooser();
        editRentToReturnField = new com.toedter.calendar.JDateChooser();
        editRentReturnedLabel = new javax.swing.JLabel();
        editRentReturnedField = new com.toedter.calendar.JDateChooser();
        editRentReturnButton = new javax.swing.JToggleButton();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        editRentCustomersPane = new javax.swing.JScrollPane();
        editRentCustomersTable = new javax.swing.JTable();
        editRentCustomerShowLabel = new javax.swing.JLabel();
        jLayeredPane2 = new javax.swing.JLayeredPane();
        editRentBooksPane = new javax.swing.JScrollPane();
        editRentBooksTable = new javax.swing.JTable();
        editRentBookShowLabel = new javax.swing.JLabel();
        rentsTablePopupMenu = new javax.swing.JPopupMenu();
        rentsTablePopupMenuEditItem = new javax.swing.JMenuItem();
        rentsTablePopupMenuReturnNowMenuItem = new javax.swing.JMenuItem();
        rentsTablePopupMenuViewCustomerMenuItem = new javax.swing.JMenuItem();
        rentsTablePopupMenuViewBookMenuItem = new javax.swing.JMenuItem();
        rentsTablePopupMenuDeleteItem = new javax.swing.JMenuItem();
        booksTablePopupMenu = new javax.swing.JPopupMenu();
        booksTablePopupMenuEditItem = new javax.swing.JMenuItem();
        booksTablePopupMenuDeleteItem = new javax.swing.JMenuItem();
        mainPanel = new javax.swing.JTabbedPane();
        booksPanel = new javax.swing.JPanel();
        booksToolbar = new javax.swing.JToolBar();
        newBookButton = new javax.swing.JButton();
        loadBookButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        booksTitleLabel = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        bookSearchTitleField = new javax.swing.JTextField();
        jSeparator6 = new javax.swing.JToolBar.Separator();
        booksAuthorLabel = new javax.swing.JLabel();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        bookSearchAuthorField = new javax.swing.JTextField();
        bookSearchButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        booksTable = new javax.swing.JTable();
        rentsPanel = new javax.swing.JPanel();
        rentsScrollPane = new javax.swing.JScrollPane();
        rentsTable = new javax.swing.JTable();
        rentsToolBar = new javax.swing.JToolBar();
        newRentButton = new javax.swing.JButton();
        loadRentsButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        rentsArchiveToggleButton = new javax.swing.JToggleButton();
        customersPanel = new javax.swing.JPanel();
        customersScrollPane = new javax.swing.JScrollPane();
        customersTable = new javax.swing.JTable();
        customersToolBar = new javax.swing.JToolBar();
        newCustomerButton = new javax.swing.JButton();
        loadCustomersButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        customerSearchFirstNameLabel = new javax.swing.JLabel();
        jSeparator10 = new javax.swing.JToolBar.Separator();
        customerSearchFirstNameField = new javax.swing.JTextField();
        jSeparator8 = new javax.swing.JToolBar.Separator();
        customerSearchSurnameLabel = new javax.swing.JLabel();
        jSeparator9 = new javax.swing.JToolBar.Separator();
        customerSearchSurnameField = new javax.swing.JTextField();
        jSeparator7 = new javax.swing.JToolBar.Separator();
        customerSearchButton = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newMenu = new javax.swing.JMenu();
        newBookMenuItem = new javax.swing.JMenuItem();
        newRentMenuItem = new javax.swing.JMenuItem();
        newCustomerMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        aboutDialog.setMinimumSize(new java.awt.Dimension(253, 250));
        aboutDialog.setResizable(false);

        aboutDialogNameLabel.setFont(new java.awt.Font("Tahoma", 0, 36));
        aboutDialogNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        aboutDialogNameLabel.setText("jLibrarian");

        aboutDialogTextAuthors.setText("2011, Josef Ludvicek, Vaclav Mach");

        aboutDialogClose.setText("Close");
        aboutDialogClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutDialogCloseActionPerformed(evt);
            }
        });

        aboutDialogTextLink.setText("http://code.google.com/jlibrarian/");

        javax.swing.GroupLayout aboutDialogLayout = new javax.swing.GroupLayout(aboutDialog.getContentPane());
        aboutDialog.getContentPane().setLayout(aboutDialogLayout);
        aboutDialogLayout.setHorizontalGroup(
            aboutDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, aboutDialogLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(aboutDialogNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(aboutDialogLayout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addGroup(aboutDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(aboutDialogTextLink)
                    .addComponent(aboutDialogTextAuthors))
                .addContainerGap(44, Short.MAX_VALUE))
            .addGroup(aboutDialogLayout.createSequentialGroup()
                .addGap(84, 84, 84)
                .addComponent(aboutDialogClose, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(97, Short.MAX_VALUE))
        );
        aboutDialogLayout.setVerticalGroup(
            aboutDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(aboutDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(aboutDialogNameLabel)
                .addGap(18, 18, 18)
                .addComponent(aboutDialogTextAuthors)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(aboutDialogTextLink)
                .addGap(26, 26, 26)
                .addComponent(aboutDialogClose, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("jlibrarian/desktop/Texts"); // NOI18N
        customerEditFrame.setTitle(bundle.getString("newCustomerFrame")); // NOI18N
        customerEditFrame.setMinimumSize(new java.awt.Dimension(400, 280));
        customerEditFrame.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentHidden(java.awt.event.ComponentEvent evt) {
                customerEditFrameComponentHidden(evt);
            }
        });

        firstNameLabel.setText(bundle.getString("fnTh")); // NOI18N

        surnameLabel.setText(bundle.getString("snTh")); // NOI18N

        cityLabel.setText(bundle.getString("cityTh")); // NOI18N

        streetLabel.setText(bundle.getString("streetTh")); // NOI18N

        telephoneLabel.setText(bundle.getString("telephoneTh")); // NOI18N

        saveCustomerButton.setText(bundle.getString("createButton")); // NOI18N
        saveCustomerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveCustomerButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout customerEditFrameLayout = new javax.swing.GroupLayout(customerEditFrame.getContentPane());
        customerEditFrame.getContentPane().setLayout(customerEditFrameLayout);
        customerEditFrameLayout.setHorizontalGroup(
            customerEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(customerEditFrameLayout.createSequentialGroup()
                .addGroup(customerEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(customerEditFrameLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(firstNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(firstNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, customerEditFrameLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(surnameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(surnameField, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE))
                    .addGroup(customerEditFrameLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(customerEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cityLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(streetLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(customerEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cityField, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
                            .addComponent(streetField, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)))
                    .addGroup(customerEditFrameLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(telephoneLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(telephoneField, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE))
                    .addGroup(customerEditFrameLayout.createSequentialGroup()
                        .addGap(145, 145, 145)
                        .addComponent(saveCustomerButton)))
                .addContainerGap())
        );
        customerEditFrameLayout.setVerticalGroup(
            customerEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(customerEditFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(customerEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(firstNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(firstNameField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(customerEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(surnameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(surnameField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(customerEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cityLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cityField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(customerEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(streetLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(streetField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(customerEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(telephoneLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(telephoneField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(saveCustomerButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bookEditFrame.setTitle(bundle.getString("newBookFrame")); // NOI18N
        bookEditFrame.setMinimumSize(new java.awt.Dimension(400, 340));
        bookEditFrame.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentHidden(java.awt.event.ComponentEvent evt) {
                bookEditFrameComponentHidden(evt);
            }
        });

        saveBookButton.setText(bundle.getString("createButton")); // NOI18N
        saveBookButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveBookButtonActionPerformed(evt);
            }
        });

        titleField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                titleFieldActionPerformed(evt);
            }
        });

        quantityLabel.setText(bundle.getString("quantityTh")); // NOI18N

        titleLabel.setText(bundle.getString("titleTh")); // NOI18N

        authorsLabel.setText(bundle.getString("authorsTh")); // NOI18N

        noteLabel.setText(bundle.getString("notesTh")); // NOI18N

        noteField.setColumns(20);
        noteField.setLineWrap(true);
        noteField.setRows(5);
        noteField.setWrapStyleWord(true);
        jScrollPane1.setViewportView(noteField);

        javax.swing.GroupLayout bookEditFrameLayout = new javax.swing.GroupLayout(bookEditFrame.getContentPane());
        bookEditFrame.getContentPane().setLayout(bookEditFrameLayout);
        bookEditFrameLayout.setHorizontalGroup(
            bookEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(bookEditFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(bookEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(bookEditFrameLayout.createSequentialGroup()
                        .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(titleField, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE))
                    .addGroup(bookEditFrameLayout.createSequentialGroup()
                        .addComponent(authorsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(authorsField, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE))
                    .addGroup(bookEditFrameLayout.createSequentialGroup()
                        .addComponent(quantityLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(quantityField, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(bookEditFrameLayout.createSequentialGroup()
                        .addComponent(noteLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(bookEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(saveBookButton, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE))))
                .addContainerGap())
        );
        bookEditFrameLayout.setVerticalGroup(
            bookEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(bookEditFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(bookEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(bookEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(authorsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(authorsField, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(bookEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(quantityLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(quantityField, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(bookEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(noteLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
                .addGap(12, 12, 12)
                .addComponent(saveBookButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23))
        );

        customersTablePopupMenuEditItem.setText(bundle.getString("editCustomerFrame")); // NOI18N
        customersTablePopupMenuEditItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customersTablePopupMenuEditItemActionPerformed(evt);
            }
        });
        customersTablePopupMenu.add(customersTablePopupMenuEditItem);

        customersTablePopupMenuDeleteItem.setText(bundle.getString("deleteEI")); // NOI18N
        customersTablePopupMenuDeleteItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customersTablePopupMenuDeleteItemActionPerformed(evt);
            }
        });
        customersTablePopupMenu.add(customersTablePopupMenuDeleteItem);

        rentEditFrame.setTitle(bundle.getString("newRentFrame")); // NOI18N
        rentEditFrame.setMinimumSize(new java.awt.Dimension(400, 500));

        editRentCustomerLabel.setText(bundle.getString("customerTh")); // NOI18N

        editRentBookLabel.setText(bundle.getString("bookTh")); // NOI18N

        saveRentButton.setText(bundle.getString("saveFI")); // NOI18N
        saveRentButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveRentButtonActionPerformed(evt);
            }
        });

        editRentBorrowedLabel.setText(bundle.getString("dtOutTh")); // NOI18N

        editRentToBeReturnedLabel.setText(bundle.getString("dateShouldIn")); // NOI18N

        editRentCustomerSearchField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                editRentCustomerSearchFieldKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                editRentCustomerSearchFieldKeyTyped(evt);
            }
        });

        editRentCustomerSearchButton.setText(bundle.getString("searchButton")); // NOI18N
        editRentCustomerSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editRentCustomerSearchButtonActionPerformed(evt);
            }
        });

        editRentBookSearchField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                editRentBookSearchFieldKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                editRentBookSearchFieldKeyTyped(evt);
            }
        });

        editRentBookSearchButton.setText(bundle.getString("searchButton")); // NOI18N
        editRentBookSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editRentBookSearchButtonActionPerformed(evt);
            }
        });

        editRentReturnedLabel.setText(bundle.getString("dtInTh")); // NOI18N

        editRentReturnButton.setText(bundle.getString("returnNowButton")); // NOI18N
        editRentReturnButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editRentReturnButtonActionPerformed(evt);
            }
        });

        editRentCustomersTable.setModel(new JLibrarianTableModel());
        editRentCustomersTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        editRentCustomersPane.setViewportView(editRentCustomersTable);

        editRentCustomersPane.setBounds(0, 0, 380, 90);
        jLayeredPane1.add(editRentCustomersPane, javax.swing.JLayeredPane.DEFAULT_LAYER);

        editRentCustomerShowLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        editRentCustomerShowLabel.setText("jLabel1");
        editRentCustomerShowLabel.setBounds(10, 10, 350, 30);
        jLayeredPane1.add(editRentCustomerShowLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        editRentBooksTable.setModel(new JLibrarianTableModel());
        editRentBooksTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        editRentBooksPane.setViewportView(editRentBooksTable);

        editRentBooksPane.setBounds(0, 0, 380, 90);
        jLayeredPane2.add(editRentBooksPane, javax.swing.JLayeredPane.DEFAULT_LAYER);

        editRentBookShowLabel.setFont(new java.awt.Font("Tahoma", 0, 18));
        editRentBookShowLabel.setText("jLabel1");
        editRentBookShowLabel.setBounds(20, 10, 350, 30);
        jLayeredPane2.add(editRentBookShowLabel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout rentEditFrameLayout = new javax.swing.GroupLayout(rentEditFrame.getContentPane());
        rentEditFrame.getContentPane().setLayout(rentEditFrameLayout);
        rentEditFrameLayout.setHorizontalGroup(
            rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rentEditFrameLayout.createSequentialGroup()
                .addGroup(rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(rentEditFrameLayout.createSequentialGroup()
                        .addGap(90, 90, 90)
                        .addComponent(saveRentButton, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(editRentReturnButton, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(rentEditFrameLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLayeredPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                            .addGroup(rentEditFrameLayout.createSequentialGroup()
                                .addComponent(editRentCustomerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(editRentCustomerSearchField, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(editRentCustomerSearchButton))
                            .addGroup(rentEditFrameLayout.createSequentialGroup()
                                .addComponent(editRentBorrowedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                                .addComponent(editRentBorrowedField, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(rentEditFrameLayout.createSequentialGroup()
                                .addGroup(rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(editRentReturnedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(editRentToBeReturnedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                                .addGroup(rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(editRentToReturnField, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(editRentReturnedField, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(rentEditFrameLayout.createSequentialGroup()
                                .addComponent(editRentBookLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(12, 12, 12)
                                .addComponent(editRentBookSearchField, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(editRentBookSearchButton))
                            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))))
                .addContainerGap())
        );
        rentEditFrameLayout.setVerticalGroup(
            rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rentEditFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(editRentCustomerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(editRentCustomerSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(editRentCustomerSearchButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(editRentBookLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(editRentBookSearchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(editRentBookSearchButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLayeredPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(editRentBorrowedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(editRentBorrowedField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(editRentToBeReturnedLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(editRentToReturnField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(editRentReturnedField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(rentEditFrameLayout.createSequentialGroup()
                        .addComponent(editRentReturnedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(rentEditFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(editRentReturnButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(saveRentButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(56, 56, 56))
        );

        rentsTablePopupMenuEditItem.setText(bundle.getString("editRentFrame")); // NOI18N
        rentsTablePopupMenuEditItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rentsTablePopupMenuEditItemActionPerformed(evt);
            }
        });
        rentsTablePopupMenu.add(rentsTablePopupMenuEditItem);

        rentsTablePopupMenuReturnNowMenuItem.setText(bundle.getString("returnNowButton")); // NOI18N
        rentsTablePopupMenuReturnNowMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rentsTablePopupMenuReturnNowMenuItemActionPerformed(evt);
            }
        });
        rentsTablePopupMenu.add(rentsTablePopupMenuReturnNowMenuItem);

        rentsTablePopupMenuViewCustomerMenuItem.setText(bundle.getString("viewCustomerMI")); // NOI18N
        rentsTablePopupMenuViewCustomerMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rentsTablePopupMenuViewCustomerMenuItemActionPerformed(evt);
            }
        });
        rentsTablePopupMenu.add(rentsTablePopupMenuViewCustomerMenuItem);

        rentsTablePopupMenuViewBookMenuItem.setText(bundle.getString("viewBookMI")); // NOI18N
        rentsTablePopupMenuViewBookMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rentsTablePopupMenuViewBookMenuItemActionPerformed(evt);
            }
        });
        rentsTablePopupMenu.add(rentsTablePopupMenuViewBookMenuItem);

        rentsTablePopupMenuDeleteItem.setText(bundle.getString("deleteEI")); // NOI18N
        rentsTablePopupMenuDeleteItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rentsTablePopupMenuDeleteItemActionPerformed(evt);
            }
        });
        rentsTablePopupMenu.add(rentsTablePopupMenuDeleteItem);

        booksTablePopupMenuEditItem.setText(bundle.getString("editBookFrame")); // NOI18N
        booksTablePopupMenuEditItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                booksTablePopupMenuEditItemActionPerformed(evt);
            }
        });
        booksTablePopupMenu.add(booksTablePopupMenuEditItem);

        booksTablePopupMenuDeleteItem.setText(bundle.getString("deleteEI")); // NOI18N
        booksTablePopupMenuDeleteItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                booksTablePopupMenuDeleteItemActionPerformed(evt);
            }
        });
        booksTablePopupMenu.add(booksTablePopupMenuDeleteItem);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("jLibrarian");
        setMinimumSize(new java.awt.Dimension(400, 300));

        mainPanel.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                mainPanelFocusGained(evt);
            }
        });

        booksToolbar.setFloatable(false);
        booksToolbar.setRollover(true);

        newBookButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jlibrarian/img/book_add.png"))); // NOI18N
        newBookButton.setText(bundle.getString("newButton")); // NOI18N
        newBookButton.setMargin(new java.awt.Insets(2, 0, 2, 28));
        newBookButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newBookButtonActionPerformed(evt);
            }
        });
        booksToolbar.add(newBookButton);

        loadBookButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jlibrarian/img/book_go.png"))); // NOI18N
        loadBookButton.setText(bundle.getString("loadButton")); // NOI18N
        loadBookButton.setMargin(new java.awt.Insets(2, 0, 2, 28));
        loadBookButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadBookButtonActionPerformed(evt);
            }
        });
        booksToolbar.add(loadBookButton);

        jSeparator2.setSeparatorSize(new java.awt.Dimension(50, 0));
        booksToolbar.add(jSeparator2);

        booksTitleLabel.setText(bundle.getString("bookSearchTitleLabel")); // NOI18N
        booksToolbar.add(booksTitleLabel);

        jSeparator4.setSeparatorSize(new java.awt.Dimension(10, 0));
        booksToolbar.add(jSeparator4);

        bookSearchTitleField.setAutoscrolls(false);
        bookSearchTitleField.setMargin(new java.awt.Insets(5, 5, 5, 5));
        bookSearchTitleField.setPreferredSize(new java.awt.Dimension(62, 24));
        bookSearchTitleField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                bookSearchTitleFieldKeyPressed(evt);
            }
        });
        booksToolbar.add(bookSearchTitleField);

        jSeparator6.setSeparatorSize(new java.awt.Dimension(10, 0));
        booksToolbar.add(jSeparator6);

        booksAuthorLabel.setText(bundle.getString("bookSearchAuthorLabel")); // NOI18N
        booksToolbar.add(booksAuthorLabel);

        jSeparator5.setSeparatorSize(new java.awt.Dimension(10, 0));
        booksToolbar.add(jSeparator5);

        bookSearchAuthorField.setMargin(new java.awt.Insets(5, 5, 5, 5));
        bookSearchAuthorField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                bookSearchAuthorFieldKeyPressed(evt);
            }
        });
        booksToolbar.add(bookSearchAuthorField);

        bookSearchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jlibrarian/img/find.png"))); // NOI18N
        bookSearchButton.setText(bundle.getString("searchButton")); // NOI18N
        bookSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bookSearchButtonActionPerformed(evt);
            }
        });
        booksToolbar.add(bookSearchButton);

        booksTable.setModel(new JLibrarianTableModel());
        booksTable.setComponentPopupMenu(booksTablePopupMenu);
        booksTable.setRowSorter(new TableRowSorter<TableModel>(booksTable.getModel()));
        booksTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        booksTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                booksTableMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(booksTable);

        javax.swing.GroupLayout booksPanelLayout = new javax.swing.GroupLayout(booksPanel);
        booksPanel.setLayout(booksPanelLayout);
        booksPanelLayout.setHorizontalGroup(
            booksPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(booksPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(booksPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
                    .addComponent(booksToolbar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE))
                .addContainerGap())
        );
        booksPanelLayout.setVerticalGroup(
            booksPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(booksPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(booksToolbar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE)
                .addContainerGap())
        );

        mainPanel.addTab(bundle.getString("pnBooks"), booksPanel); // NOI18N

        rentsTable.setModel(new JLibrarianTableModel());
        rentsTable.setComponentPopupMenu(rentsTablePopupMenu);
        rentsTable.setRowSorter(new TableRowSorter<TableModel>(rentsTable.getModel()));
        rentsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        rentsTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rentsTableMouseClicked(evt);
            }
        });
        rentsScrollPane.setViewportView(rentsTable);

        rentsToolBar.setFloatable(false);
        rentsToolBar.setRollover(true);

        newRentButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jlibrarian/img/page_add.png"))); // NOI18N
        newRentButton.setText(bundle.getString("newButton")); // NOI18N
        newRentButton.setMargin(new java.awt.Insets(2, 0, 2, 28));
        newRentButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newRentButtonActionPerformed(evt);
            }
        });
        rentsToolBar.add(newRentButton);

        loadRentsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jlibrarian/img/page_go.png"))); // NOI18N
        loadRentsButton.setText(bundle.getString("loadButton")); // NOI18N
        loadRentsButton.setMargin(new java.awt.Insets(2, 0, 2, 28));
        loadRentsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadRentsButtonActionPerformed(evt);
            }
        });
        rentsToolBar.add(loadRentsButton);

        jSeparator3.setSeparatorSize(new java.awt.Dimension(24, 0));
        rentsToolBar.add(jSeparator3);

        rentsArchiveToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jlibrarian/img/folder_table.png"))); // NOI18N
        rentsArchiveToggleButton.setText(bundle.getString("archiveToggleButton")); // NOI18N
        rentsArchiveToggleButton.setFocusable(false);
        rentsArchiveToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        rentsArchiveToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rentsArchiveToggleButtonActionPerformed(evt);
            }
        });
        rentsToolBar.add(rentsArchiveToggleButton);

        javax.swing.GroupLayout rentsPanelLayout = new javax.swing.GroupLayout(rentsPanel);
        rentsPanel.setLayout(rentsPanelLayout);
        rentsPanelLayout.setHorizontalGroup(
            rentsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, rentsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(rentsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(rentsScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
                    .addComponent(rentsToolBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE))
                .addContainerGap())
        );
        rentsPanelLayout.setVerticalGroup(
            rentsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rentsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rentsToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(rentsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE)
                .addContainerGap())
        );

        mainPanel.addTab(bundle.getString("pnRents"), rentsPanel); // NOI18N

        customersPanel.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                customersPanelFocusGained(evt);
            }
        });

        customersTable.setModel(new JLibrarianTableModel());
        customersTable.setComponentPopupMenu(customersTablePopupMenu);
        customersTable.setDropMode(javax.swing.DropMode.ON);
        customersTable.setRowSorter(new TableRowSorter<TableModel>(customersTable.getModel()));
        customersTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        customersTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                customersTableMouseClicked(evt);
            }
        });
        customersScrollPane.setViewportView(customersTable);

        customersToolBar.setFloatable(false);
        customersToolBar.setRollover(true);

        newCustomerButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jlibrarian/img/user_add.png"))); // NOI18N
        newCustomerButton.setText(bundle.getString("newButton")); // NOI18N
        newCustomerButton.setMargin(new java.awt.Insets(2, 0, 2, 28));
        newCustomerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newCustomerButtonActionPerformed(evt);
            }
        });
        customersToolBar.add(newCustomerButton);

        loadCustomersButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jlibrarian/img/user_go.png"))); // NOI18N
        loadCustomersButton.setText(bundle.getString("loadButton")); // NOI18N
        loadCustomersButton.setMargin(new java.awt.Insets(2, 0, 2, 28));
        loadCustomersButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadCustomersButtonActionPerformed(evt);
            }
        });
        customersToolBar.add(loadCustomersButton);

        jSeparator1.setSeparatorSize(new java.awt.Dimension(50, 0));
        customersToolBar.add(jSeparator1);

        customerSearchFirstNameLabel.setText(bundle.getString("customerSearchFirstNlabel")); // NOI18N
        customersToolBar.add(customerSearchFirstNameLabel);

        jSeparator10.setSeparatorSize(new java.awt.Dimension(10, 0));
        customersToolBar.add(jSeparator10);

        customerSearchFirstNameField.setAutoscrolls(false);
        customerSearchFirstNameField.setMargin(new java.awt.Insets(5, 5, 5, 5));
        customerSearchFirstNameField.setPreferredSize(new java.awt.Dimension(62, 24));
        customerSearchFirstNameField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                customerSearchFirstNameFieldKeyPressed(evt);
            }
        });
        customersToolBar.add(customerSearchFirstNameField);

        jSeparator8.setSeparatorSize(new java.awt.Dimension(10, 0));
        customersToolBar.add(jSeparator8);

        customerSearchSurnameLabel.setText(bundle.getString("customerSearchSurnameLabel")); // NOI18N
        customersToolBar.add(customerSearchSurnameLabel);

        jSeparator9.setSeparatorSize(new java.awt.Dimension(10, 0));
        customersToolBar.add(jSeparator9);

        customerSearchSurnameField.setMargin(new java.awt.Insets(5, 5, 5, 5));
        customerSearchSurnameField.setPreferredSize(new java.awt.Dimension(60, 24));
        customerSearchSurnameField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                customerSearchSurnameFieldKeyPressed(evt);
            }
        });
        customersToolBar.add(customerSearchSurnameField);

        jSeparator7.setSeparatorSize(new java.awt.Dimension(10, 0));
        customersToolBar.add(jSeparator7);

        customerSearchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jlibrarian/img/find.png"))); // NOI18N
        customerSearchButton.setText(bundle.getString("searchButton")); // NOI18N
        customerSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customerSearchButtonActionPerformed(evt);
            }
        });
        customersToolBar.add(customerSearchButton);

        javax.swing.GroupLayout customersPanelLayout = new javax.swing.GroupLayout(customersPanel);
        customersPanel.setLayout(customersPanelLayout);
        customersPanelLayout.setHorizontalGroup(
            customersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, customersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(customersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(customersScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE)
                    .addComponent(customersToolBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE))
                .addContainerGap())
        );
        customersPanelLayout.setVerticalGroup(
            customersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(customersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(customersToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(customersScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
                .addContainerGap())
        );

        mainPanel.addTab(bundle.getString("pnCustomers"), customersPanel); // NOI18N

        menuBar.setName("jLibrarian"); // NOI18N

        fileMenu.setMnemonic('f');
        fileMenu.setText(bundle.getString("mbFile")); // NOI18N

        newMenu.setText(bundle.getString("newFI")); // NOI18N

        newBookMenuItem.setText(bundle.getString("newBookFI")); // NOI18N
        newBookMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newBookMenuItemActionPerformed(evt);
            }
        });
        newMenu.add(newBookMenuItem);

        newRentMenuItem.setText(bundle.getString("newRentFI")); // NOI18N
        newRentMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newRentMenuItemActionPerformed(evt);
            }
        });
        newMenu.add(newRentMenuItem);

        newCustomerMenuItem.setText(bundle.getString("newCustomerFI")); // NOI18N
        newCustomerMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newCustomerMenuItemActionPerformed(evt);
            }
        });
        newMenu.add(newCustomerMenuItem);

        fileMenu.add(newMenu);

        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText(bundle.getString("exitFI")); // NOI18N
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setMnemonic('h');
        helpMenu.setText(bundle.getString("mbHelp")); // NOI18N

        aboutMenuItem.setMnemonic('a');
        aboutMenuItem.setText(bundle.getString("aboutHI")); // NOI18N
        aboutMenuItem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                aboutMenuItemMouseClicked(evt);
            }
        });
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 626, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void aboutMenuItemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_aboutMenuItemMouseClicked
        // TODO add your handling code here:
        aboutDialog.setVisible(true);
    }//GEN-LAST:event_aboutMenuItemMouseClicked

    private void aboutDialogCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutDialogCloseActionPerformed
        // TODO add your handling code here:
        aboutDialog.setVisible(false);
    }//GEN-LAST:event_aboutDialogCloseActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        aboutDialog.setVisible(true);
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void saveCustomerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveCustomerButtonActionPerformed
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                Customer returned = createCustomer();
                if (returned != null) {
                    clearEditCustomerFrame();
                    customerEditFrame.setVisible(false);
                    customersTableReload();
                    frameCustomerId = -1;
                } else {
                    //     JOptionPane.showMessageDialog(null, "There was a error during customer creating.");
                }
            }
        });
    }//GEN-LAST:event_saveCustomerButtonActionPerformed

    private void saveBookButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBookButtonActionPerformed

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                Book returned = createBook();
                if (returned != null) {
                    clearEditBookFrame();
                    bookEditFrame.setVisible(false);
                    booksTableReload();
                    //init frameBookID
                    frameBookId = -1;
                } else {
                    //    JOptionPane.showMessageDialog(null, "There was a error during book creating.");
                }
            }
        });
    }//GEN-LAST:event_saveBookButtonActionPerformed

    /**
     * This method clear text fields in bookEditFrame
     */
    private void clearEditBookFrame() {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                quantityField.setText("");
                authorsField.setText("");
                titleField.setText("");
                noteField.setText("");

                bookEditFrame.setTitle(MyBundle.getProperty("newBookFrame"));
                saveBookButton.setText(MyBundle.getProperty("createButton"));
                frameBookId = -1;
            }
        });
    }

    private void clearEditCustomerFrame() {

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                firstNameField.setText("");
                surnameField.setText("");
                telephoneField.setText("");
                streetField.setText("");
                cityField.setText("");
                frameCustomerId = -1;

                customerEditFrame.setTitle(MyBundle.getProperty("newCustomerFrame"));
                saveCustomerButton.setText(MyBundle.getProperty("createButton"));
            }
        });
    }

    /**
     * This method takes book ID and fills frame with strings from DB
     * @param bookID int book id
     */
    private void fillEditBookFrame(int bookID) {

        BookManager bm = new BookManagerImpl(DbManager.getDataSource());
        Book b = bm.findBookById(bookID);

        authorsField.setText(b.getAuthors());
        titleField.setText(b.getTitle());
        quantityField.setText(Integer.toString(b.getQuantity()));
        noteField.setText(b.getNote());


        bookEditFrame.setTitle(MyBundle.getProperty("editBookFrame"));
        saveBookButton.setText(MyBundle.getProperty("saveButton"));
    }

    /**
     * This method takes customer ID and fills customer edit frame with properities
     * @param customerID int ID
     */
    private void fillEditCustomerFrame(int customerID) {
        CustomerManager cm = new CustomerManagerImpl((DbManager.getDataSource()));
        Customer c = cm.findCustomerById(customerID);

        firstNameField.setText(c.getFirstName());
        surnameField.setText(c.getSurname());
        streetField.setText(c.getStreet());
        telephoneField.setText(c.getTelephone());
        cityField.setText(c.getCity());

        customerEditFrame.setTitle(MyBundle.getProperty("editCustomerFrame"));
        saveCustomerButton.setText(MyBundle.getProperty("saveButton"));
    }

    /**
     * This method takes customer ID and fills customer edit frame with properities
     * @param customerID int ID
     */
    private void fillEditRentFrame(int rentID) {
        RentManager rm = new RentManagerImpl((DbManager.getDataSource()));
        Rent r = rm.findRentById(rentID);

        editRentBorrowedField.setCalendar(r.getBorrowed());
        editRentToReturnField.setCalendar(r.getToReturn());
        editRentReturnedField.setCalendar(r.getReturned());

        editRentReturnButton.setVisible(true);

        editRentCustomersPane.setVisible(false);
        editRentCustomerShowLabel.setVisible(true);
        editRentCustomerShowLabel.setText(r.getCustomer().toString());
        editRentBooksPane.setVisible(false);
        editRentBookShowLabel.setVisible(true);
        editRentBookShowLabel.setText(r.getBook().toString());
        editRentCustomerSearchButton.setVisible(false);
        editRentBookSearchButton.setVisible(false);
        editRentCustomerSearchField.setVisible(false);
        editRentBookSearchField.setVisible(false);

        rentEditFrame.setTitle(MyBundle.getProperty("editRentFrame"));
        saveRentButton.setText(MyBundle.getProperty("saveButton"));
    }

    private void clearEditRentFrame() {

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                editRentBorrowedField.setDate(new Date());

                Calendar toReturn = Calendar.getInstance();
                toReturn.add(Calendar.DAY_OF_MONTH, JLibrarianDesktop.DEFAULT_DAYS);
                editRentToReturnField.setDate(toReturn.getTime());

                editRentReturnedField.setDate(null);

                rentEditFrame.setTitle(MyBundle.getProperty("newRentFrame"));
                saveRentButton.setText(MyBundle.getProperty("createButton"));
                editRentReturnButton.setVisible(false);

                editRentCustomersPane.setVisible(true);
                editRentCustomerShowLabel.setVisible(false);
                editRentBooksPane.setVisible(true);
                editRentBookShowLabel.setVisible(false);
                editRentCustomerSearchButton.setVisible(true);
                editRentBookSearchButton.setVisible(true);
                editRentCustomerSearchField.setVisible(true);
                editRentBookSearchField.setVisible(true);
                frameBookId = -1;

                JLibrarianTableModel model = (JLibrarianTableModel) editRentBooksTable.getModel();
                model.clear();
            }
        });


    }

    private boolean confirmDeleteDialog() {
        Object[] options = {
            MyBundle.getProperty("yes"),
            MyBundle.getProperty("no")
        };

        int n = JOptionPane.showOptionDialog(this,
                MyBundle.getProperty("deleteMsg"),
                MyBundle.getProperty("deleteTitle"),
                JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[1]);

        return n == 0 ? true : false;
    }

    /**
     * This method takes string and returns int
     * @param quantity string to parse
     * @return parsed number, -1 if NumberFormatException
     */
    private int parseQuantity(String quantity) {
        int i = -1;
        try {
            i = Integer.parseInt(quantity);
        } catch (NumberFormatException nfe) {
        }
        return i;
    }

    private Book createBook() {
        if (!(titleField.getText().length() > 0
                && authorsField.getText().length() > 0
                && quantityField.getText().length() > 0)) {
            JOptionPane.showMessageDialog(null, MyBundle.getProperty("fillAllValuesMsg"));
            return null;
        }


        if (parseQuantity(quantityField.getText()) <= 0) {
            JOptionPane.showMessageDialog(null, MyBundle.getProperty("invalidQuantityMsg"));
            return null;
        }

        Book b = new Book();
        b.setAuthors(authorsField.getText());
        b.setTitle(titleField.getText());
        b.setNote(noteField.getText());
        b.setQuantity(parseQuantity(quantityField.getText()));

        BookManager bm = new BookManagerImpl(DbManager.getDataSource());

        if (frameBookId >= 0) {
            b.setBid(frameBookId);
            return bm.updateBook(b) ? b : null;
        }

        return bm.createBook(b);
    }

    private Customer createCustomer() {
        if (!(firstNameField.getText().length() > 0
                && surnameField.getText().length() > 0
                && telephoneField.getText().length() > 0
                && cityField.getText().length() > 0
                && streetField.getText().length() > 0)) {
            JOptionPane.showMessageDialog(null, MyBundle.getProperty("fillAllValuesMsg"));
            return null;
        }
        Customer c = new Customer();
        c.setFirstName(firstNameField.getText());
        c.setSurname(surnameField.getText());
        c.setTelephone(telephoneField.getText());
        c.setStreet(streetField.getText());
        c.setCity(cityField.getText());
        c.setBorn(Calendar.getInstance());

        CustomerManager cm = new CustomerManagerImpl(DbManager.getDataSource());
        if (frameCustomerId >= 0) {
            c.setCid(frameCustomerId);
            return cm.updateCustomer(c) ? c : null;
        }
        return cm.createCustomer(c);

    }

    private void searchBooks() {
       SwingWorker sw = new SearchBooksWorker();
       sw.execute();
    }

    private void searchCustomers() {
        SwingWorker sw = new SearchCustomersWorker();
        sw.execute();
    }

    private void titleFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_titleFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_titleFieldActionPerformed

    private void newBookMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newBookMenuItemActionPerformed
        // TODO add your handling code here:
        bookEditFrame.setVisible(true);
    }//GEN-LAST:event_newBookMenuItemActionPerformed

    private void mainPanelFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_mainPanelFocusGained
        // 
    }//GEN-LAST:event_mainPanelFocusGained

    private void customersPanelFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_customersPanelFocusGained
        this.customersTableReload();
    }//GEN-LAST:event_customersPanelFocusGained

    private void saveRentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveRentButtonActionPerformed
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {


                Rent returned;

                if (frameRentId >= 0) {
                    returned = updateRent();
                } else {
                    returned = createRent();
                }

                if (returned != null) {
                    clearEditRentFrame();
                    rentEditFrame.setVisible(false);
                    rentsTableReload();

                }
            }
        });
    }//GEN-LAST:event_saveRentButtonActionPerformed

    private void newRentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newRentButtonActionPerformed
        clearEditRentFrame();
        rentEditFrame.setVisible(true);
    }//GEN-LAST:event_newRentButtonActionPerformed

    private void newRentMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newRentMenuItemActionPerformed
        clearEditRentFrame();
        rentEditFrame.setVisible(true);
    }//GEN-LAST:event_newRentMenuItemActionPerformed

    private void newCustomerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newCustomerMenuItemActionPerformed
        customerEditFrame.setVisible(true);
    }//GEN-LAST:event_newCustomerMenuItemActionPerformed

    private void newBookButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newBookButtonActionPerformed
        bookEditFrame.setVisible(true);
    }//GEN-LAST:event_newBookButtonActionPerformed

    private void bookSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bookSearchButtonActionPerformed
        searchBooks();
    }//GEN-LAST:event_bookSearchButtonActionPerformed

    private void loadBookButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadBookButtonActionPerformed
        booksTableReload();
    }//GEN-LAST:event_loadBookButtonActionPerformed

    private void bookEditFrameComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_bookEditFrameComponentHidden
        clearEditBookFrame();
    }//GEN-LAST:event_bookEditFrameComponentHidden

    private void customerSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customerSearchButtonActionPerformed
        searchCustomers();
}//GEN-LAST:event_customerSearchButtonActionPerformed

    private void loadCustomersButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadCustomersButtonActionPerformed
        this.customersTableReload();
}//GEN-LAST:event_loadCustomersButtonActionPerformed

    private void newCustomerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newCustomerButtonActionPerformed
        // opens window with adding customer
        customerEditFrame.setVisible(true);
}//GEN-LAST:event_newCustomerButtonActionPerformed

    private void bookSearchTitleFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_bookSearchTitleFieldKeyPressed
        if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
            this.searchBooks();
        }
    }//GEN-LAST:event_bookSearchTitleFieldKeyPressed

    private void bookSearchAuthorFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_bookSearchAuthorFieldKeyPressed
        if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
            this.searchBooks();
        }
    }//GEN-LAST:event_bookSearchAuthorFieldKeyPressed

    private void customerSearchFirstNameFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_customerSearchFirstNameFieldKeyPressed
        if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
            this.searchCustomers();
        }
    }//GEN-LAST:event_customerSearchFirstNameFieldKeyPressed

    private void customerSearchSurnameFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_customerSearchSurnameFieldKeyPressed
        if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
            this.searchCustomers();
        }
    }//GEN-LAST:event_customerSearchSurnameFieldKeyPressed

    private void editRentCustomerSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editRentCustomerSearchButtonActionPerformed
        editRentCustomerSearch();
    }//GEN-LAST:event_editRentCustomerSearchButtonActionPerformed

    private void editRentCustomerSearchFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_editRentCustomerSearchFieldKeyTyped
        String searched = editRentCustomerSearchField.getText();
        if (searched.length() >= (JLibrarianDesktop.SEARCH_CHARACTERS - 1)) {
            editRentCustomerSearch();
        }
    }//GEN-LAST:event_editRentCustomerSearchFieldKeyTyped

    private void editRentCustomerSearchFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_editRentCustomerSearchFieldKeyPressed
        if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
            this.editRentCustomerSearch();
        }
    }//GEN-LAST:event_editRentCustomerSearchFieldKeyPressed

    private void editRentBookSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editRentBookSearchButtonActionPerformed
        editRentBookSearch();
    }//GEN-LAST:event_editRentBookSearchButtonActionPerformed

    private void editRentBookSearchFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_editRentBookSearchFieldKeyTyped
        String searched = editRentBookSearchField.getText();
        if (searched.length() >= (JLibrarianDesktop.SEARCH_CHARACTERS - 1)) {
            editRentBookSearch();
        }
    }//GEN-LAST:event_editRentBookSearchFieldKeyTyped

    private void editRentBookSearchFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_editRentBookSearchFieldKeyPressed
        if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
            this.editRentBookSearch();
        }
    }//GEN-LAST:event_editRentBookSearchFieldKeyPressed

    private void loadRentsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadRentsButtonActionPerformed
        rentsTableReload();
    }//GEN-LAST:event_loadRentsButtonActionPerformed

    private void rentsArchiveToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rentsArchiveToggleButtonActionPerformed
        // TODO add your handling code here:
        rentsTableReload();
    }//GEN-LAST:event_rentsArchiveToggleButtonActionPerformed

    private void editRentReturnButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editRentReturnButtonActionPerformed
        editRentReturnedField.setCalendar(Calendar.getInstance());
        saveRentButtonActionPerformed(null);
    }//GEN-LAST:event_editRentReturnButtonActionPerformed

    private void rentsTablePopupMenuEditItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rentsTablePopupMenuEditItemActionPerformed
        editRentShowFrame();
    }//GEN-LAST:event_rentsTablePopupMenuEditItemActionPerformed

    private void rentsTablePopupMenuReturnNowMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rentsTablePopupMenuReturnNowMenuItemActionPerformed
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {

                int rentId = getIdFromSelectedRow(rentsTable);

                // if not valid
                if (rentId <= 0) {
                    return;
                }

                RentManager rm = new RentManagerImpl(DbManager.getDataSource());

                Rent r = rm.findRentById(rentId);

                Calendar returnedC = Calendar.getInstance();
                r.setReturned(returnedC);

                rm.updateRent(r);

                // refresh
                rentsTableReload();
            }
        });
    }//GEN-LAST:event_rentsTablePopupMenuReturnNowMenuItemActionPerformed

    private void rentsTablePopupMenuViewCustomerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rentsTablePopupMenuViewCustomerMenuItemActionPerformed
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {

                int selectedRow = rentsTable.getSelectedRow();
                int customerPos = 2;
                if (selectedRow == -1) {
                    return;
                }

                Object customerO = rentsTable.getValueAt(selectedRow, customerPos);
                if (!(customerO instanceof Customer)) {
                    return;
                }

                Customer customer = (Customer) customerO;

                int customerID = customer.getCid();
                //valid?
                if (customerID <= 0) {
                    return;
                }

                fillEditCustomerFrame(customerID);
                frameCustomerId = customerID;
                customerEditFrame.setVisible(true);
            }
        });

    }//GEN-LAST:event_rentsTablePopupMenuViewCustomerMenuItemActionPerformed

    private void booksTablePopupMenuEditItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_booksTablePopupMenuEditItemActionPerformed
        editBookShowFrame();
    }//GEN-LAST:event_booksTablePopupMenuEditItemActionPerformed

    private void customersTablePopupMenuEditItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customersTablePopupMenuEditItemActionPerformed
        editCustomerShowFrame();
    }//GEN-LAST:event_customersTablePopupMenuEditItemActionPerformed

    private void customerEditFrameComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_customerEditFrameComponentHidden
        clearEditCustomerFrame();
    }//GEN-LAST:event_customerEditFrameComponentHidden

    private void booksTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_booksTableMouseClicked
        if (evt.getClickCount() == 2) {
            editBookShowFrame();
        }
    }//GEN-LAST:event_booksTableMouseClicked

    private void customersTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_customersTableMouseClicked
        if (evt.getClickCount() == 2) {
            editCustomerShowFrame();
        }
    }//GEN-LAST:event_customersTableMouseClicked

    private void rentsTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rentsTableMouseClicked
        if (evt.getClickCount() == 2) {
            editRentShowFrame();
        }
    }//GEN-LAST:event_rentsTableMouseClicked

    private void rentsTablePopupMenuViewBookMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rentsTablePopupMenuViewBookMenuItemActionPerformed
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {

                int selectedRow = rentsTable.getSelectedRow();
                int bookPos = 1;
                if (selectedRow == -1) {
                    return;
                }

                Object bookO = rentsTable.getValueAt(selectedRow, bookPos);
                if (!(bookO instanceof Book)) {
                    return;
                }

                Book book = (Book) bookO;

                int bookID = book.getBid();
                //valid?
                if (bookID <= 0) {
                    return;
                }

                fillEditBookFrame(bookID);
                frameBookId = bookID;
                bookEditFrame.setVisible(true);
            }
        });
    }//GEN-LAST:event_rentsTablePopupMenuViewBookMenuItemActionPerformed

    private void booksTablePopupMenuDeleteItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_booksTablePopupMenuDeleteItemActionPerformed
        deleteBookEntry();
    }//GEN-LAST:event_booksTablePopupMenuDeleteItemActionPerformed

    private void rentsTablePopupMenuDeleteItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rentsTablePopupMenuDeleteItemActionPerformed
        deleteRentEntry();
    }//GEN-LAST:event_rentsTablePopupMenuDeleteItemActionPerformed

    private void customersTablePopupMenuDeleteItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customersTablePopupMenuDeleteItemActionPerformed
        deleteCustomerEntry();
    }//GEN-LAST:event_customersTablePopupMenuDeleteItemActionPerformed

    private void deleteBookEntry() {
        if (confirmDeleteDialog()) {
            int id = getIdFromSelectedRow(booksTable);
            BookManager m = new BookManagerImpl(DbManager.getDataSource());
            m.deleteBook(m.findBookById(id));
            booksTableReload();
        }
    }

    private void deleteCustomerEntry() {
        if (confirmDeleteDialog()) {
            int id = getIdFromSelectedRow(customersTable);
            CustomerManager m = new CustomerManagerImpl(DbManager.getDataSource());
            m.deleteCustomer(m.findCustomerById(id));
            customersTableReload();
        }
    }

    private void deleteRentEntry() {
        if (confirmDeleteDialog()) {
            int id = getIdFromSelectedRow(rentsTable);
            RentManager m = new RentManagerImpl(DbManager.getDataSource());
            m.deleteRent(m.findRentById(id));
            rentsTableReload();
        }
    }

    private void editBookShowFrame() {

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                int bookID = getIdFromSelectedRow(booksTable);

                // if not valid
                if (bookID <= 0) {
                    return;
                }
                fillEditBookFrame(bookID);
                frameBookId = bookID;
                bookEditFrame.setVisible(true);
            }
        });
    }

    private void editCustomerShowFrame() {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                int customerID = getIdFromSelectedRow(customersTable);
                //valid?
                if (customerID <= 0) {
                    return;
                }

                fillEditCustomerFrame(customerID);
                frameCustomerId = customerID;
                customerEditFrame.setVisible(true);
            }
        });
    }

    private void editRentShowFrame() {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                int rentID = getIdFromSelectedRow(rentsTable);
                //valid?
                if (rentID <= 0) {
                    return;
                }

                fillEditRentFrame(rentID);
                frameRentId = rentID;
                rentEditFrame.setVisible(true);
            }
        });
    }

    private void editRentCustomerSearch() {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                String searched = editRentCustomerSearchField.getText();
                Collection<Customer> c = new HashSet<Customer>();
                CustomerManager cm = new CustomerManagerImpl(DbManager.getDataSource());
                c.addAll(cm.findCustomerByNames(null, searched));
                c.addAll(cm.findCustomerByNames(searched, null));

                // c obsahuje nalezene
                TableModel model = editRentCustomersTable.getModel();
                if (!(model instanceof JLibrarianTableModel)) {
                    throw new JLibException("Table model not valid.");
                }
                String[] columns = {"cid", "firstName", "surname", "city", "street", "telephone"};
                String[] columnNames = MyBundle.getCustomersColumnNames();

                JLibrarianTableModel jmodel = (JLibrarianTableModel) model;
                jmodel.setColumnNames(columnNames);
                jmodel.setColumns(columns);

                jmodel.setDataFromCollection(c);
            }
        });
    }
    //IDs
    private static int frameBookId = -1;
    private static int frameCustomerId = -1;
    private static int frameRentId = -1;

    private int getIdFromSelectedRow(JTable table) {
        return getNumberFromSelectedRow(table, 0);
    }

    private int getNumberFromSelectedRow(JTable table, int col) {
        int row = table.getSelectedRow();
        if (row == -1) {
            return -1;
        }

        return (Integer) table.getModel().getValueAt(row, col);
    }

    private Rent createRent() {

        int customerId = this.getIdFromSelectedRow(editRentCustomersTable);
        int bookId = this.getIdFromSelectedRow(editRentBooksTable);
        Date borrowed = editRentBorrowedField.getDate();
        Date toReturn = editRentToReturnField.getDate();
        Date returned = editRentReturnedField.getDate();

        Calendar yesterday = Calendar.getInstance();
        yesterday.add(Calendar.DAY_OF_MONTH, -1);

        // checks inputs
        if (borrowed == null || toReturn == null || customerId <= 0 || bookId <= 0) {
            JOptionPane.showMessageDialog(null, MyBundle.getProperty("fillAllValuesMsg"));
            return null;
        }

        // checks dates
        if (!(borrowed.compareTo(yesterday.getTime()) > 0)
                && (toReturn.compareTo(new Date())) >= 0
                && customerId >= 0
                && bookId >= 0) {
            JOptionPane.showMessageDialog(null, MyBundle.getProperty("invalidDateMsg"));
            return null;
        }

        BookManager bm = new BookManagerImpl(DbManager.getDataSource());
        Book borrowedBook = bm.findBookById(bookId);
        CustomerManager cm = new CustomerManagerImpl(DbManager.getDataSource());
        RentManager rm = new RentManagerImpl(DbManager.getDataSource());

        // checks availability
        if (borrowedBook.getAvailable() <= 0) {
            JOptionPane.showMessageDialog(null, MyBundle.getProperty("bookNotAvailableMsg"));
            return null;
        }

        Rent r = new Rent();
        r.setBook(borrowedBook);
        r.setCustomer(cm.findCustomerById(customerId));

        Calendar borrowedC = Calendar.getInstance();
        borrowedC.setTime(borrowed);
        r.setBorrowed(borrowedC);

        if (returned != null) {
            Calendar returnedC = Calendar.getInstance();
            returnedC.setTime(returned);
            r.setReturned(returnedC);
        }

        Calendar toReturnC = Calendar.getInstance();
        toReturnC.setTime(toReturn);
        r.setToReturn(toReturnC);


        return rm.createRent(r);
    }

    private Rent updateRent() {

        Date borrowed = editRentBorrowedField.getDate();
        Date toReturn = editRentToReturnField.getDate();
        Date returned = editRentReturnedField.getDate();


        // checks inputs
        if (borrowed == null || toReturn == null) {
            JOptionPane.showMessageDialog(null, MyBundle.getProperty("fillAllValuesMsg"));
            return null;
        }

        RentManager rm = new RentManagerImpl(DbManager.getDataSource());


        Rent r = rm.findRentById(frameRentId);

        if (r == null) {
            throw new JLibException("Rent not found when saving");
        }

        Calendar borrowedC = Calendar.getInstance();
        borrowedC.setTime(borrowed);
        r.setBorrowed(borrowedC);

        if (returned != null) {
            Calendar returnedC = Calendar.getInstance();
            returnedC.setTime(returned);
            r.setReturned(returnedC);
        }

        Calendar toReturnC = Calendar.getInstance();
        toReturnC.setTime(toReturn);
        r.setToReturn(toReturnC);


        return (rm.updateRent(r)) ? r : null;
    }

    private void editRentBookSearch() {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                String searched = editRentBookSearchField.getText();
                Collection<Book> b = new HashSet<Book>();
                BookManager cm = new BookManagerImpl(DbManager.getDataSource());
                b.addAll(cm.findBooksByTitle(searched));
                b.addAll(cm.findBooksByAuthors(searched));

                // c obsahuje nalezene
                TableModel model = editRentBooksTable.getModel();
                if (!(model instanceof JLibrarianTableModel)) {
                    throw new JLibException("Table model not valid.");
                }
                String[] columns = {"bid", "title", "authors", "available"};
                String[] allColumnNames = MyBundle.getBooksColumnNames();
                String[] columnNames = {allColumnNames[0], allColumnNames[1], allColumnNames[2], allColumnNames[4]};

                JLibrarianTableModel jmodel = (JLibrarianTableModel) model;
                jmodel.setColumnNames(columnNames);
                jmodel.setColumns(columns);

                jmodel.setDataFromCollection(b);

            }
        });
    }

    private void booksTableReload() {
        SwingWorker sw = new BooksTableReloadWorker();
        sw.execute();

    }

    private void customersTableReload() {
        SwingWorker sw = new CustomersTableReloadWorker();
        sw.execute();
    }

    private void rentsTableReload() {
        SwingWorker sw = new RentsTableReloadWorker();
        sw.execute();

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog aboutDialog;
    private javax.swing.JButton aboutDialogClose;
    private javax.swing.JLabel aboutDialogNameLabel;
    private javax.swing.JLabel aboutDialogTextAuthors;
    private javax.swing.JLabel aboutDialogTextLink;
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JTextField authorsField;
    private javax.swing.JLabel authorsLabel;
    private javax.swing.JFrame bookEditFrame;
    private javax.swing.JTextField bookSearchAuthorField;
    private javax.swing.JButton bookSearchButton;
    private javax.swing.JTextField bookSearchTitleField;
    private javax.swing.JLabel booksAuthorLabel;
    private javax.swing.JPanel booksPanel;
    private javax.swing.JTable booksTable;
    private javax.swing.JPopupMenu booksTablePopupMenu;
    private javax.swing.JMenuItem booksTablePopupMenuDeleteItem;
    private javax.swing.JMenuItem booksTablePopupMenuEditItem;
    private javax.swing.JLabel booksTitleLabel;
    private javax.swing.JToolBar booksToolbar;
    private javax.swing.JTextField cityField;
    private javax.swing.JLabel cityLabel;
    private javax.swing.JFrame customerEditFrame;
    private javax.swing.JButton customerSearchButton;
    private javax.swing.JTextField customerSearchFirstNameField;
    private javax.swing.JLabel customerSearchFirstNameLabel;
    private javax.swing.JTextField customerSearchSurnameField;
    private javax.swing.JLabel customerSearchSurnameLabel;
    private javax.swing.JPanel customersPanel;
    private javax.swing.JScrollPane customersScrollPane;
    private javax.swing.JTable customersTable;
    private javax.swing.JPopupMenu customersTablePopupMenu;
    private javax.swing.JMenuItem customersTablePopupMenuDeleteItem;
    private javax.swing.JMenuItem customersTablePopupMenuEditItem;
    private javax.swing.JToolBar customersToolBar;
    private javax.swing.JLabel editRentBookLabel;
    private javax.swing.JButton editRentBookSearchButton;
    private javax.swing.JTextField editRentBookSearchField;
    private javax.swing.JLabel editRentBookShowLabel;
    private javax.swing.JScrollPane editRentBooksPane;
    private javax.swing.JTable editRentBooksTable;
    private com.toedter.calendar.JDateChooser editRentBorrowedField;
    private javax.swing.JLabel editRentBorrowedLabel;
    private javax.swing.JLabel editRentCustomerLabel;
    private javax.swing.JButton editRentCustomerSearchButton;
    private javax.swing.JTextField editRentCustomerSearchField;
    private javax.swing.JLabel editRentCustomerShowLabel;
    private javax.swing.JScrollPane editRentCustomersPane;
    private javax.swing.JTable editRentCustomersTable;
    private javax.swing.JToggleButton editRentReturnButton;
    private com.toedter.calendar.JDateChooser editRentReturnedField;
    private javax.swing.JLabel editRentReturnedLabel;
    private javax.swing.JLabel editRentToBeReturnedLabel;
    private com.toedter.calendar.JDateChooser editRentToReturnField;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JTextField firstNameField;
    private javax.swing.JLabel firstNameLabel;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JLayeredPane jLayeredPane2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator10;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JToolBar.Separator jSeparator6;
    private javax.swing.JToolBar.Separator jSeparator7;
    private javax.swing.JToolBar.Separator jSeparator8;
    private javax.swing.JToolBar.Separator jSeparator9;
    private javax.swing.JButton loadBookButton;
    private javax.swing.JButton loadCustomersButton;
    private javax.swing.JButton loadRentsButton;
    private javax.swing.JTabbedPane mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JButton newBookButton;
    private javax.swing.JMenuItem newBookMenuItem;
    private javax.swing.JButton newCustomerButton;
    private javax.swing.JMenuItem newCustomerMenuItem;
    private javax.swing.JMenu newMenu;
    private javax.swing.JButton newRentButton;
    private javax.swing.JMenuItem newRentMenuItem;
    private javax.swing.JTextArea noteField;
    private javax.swing.JLabel noteLabel;
    private javax.swing.JTextField quantityField;
    private javax.swing.JLabel quantityLabel;
    private javax.swing.JFrame rentEditFrame;
    private javax.swing.JToggleButton rentsArchiveToggleButton;
    private javax.swing.JPanel rentsPanel;
    private javax.swing.JScrollPane rentsScrollPane;
    private javax.swing.JTable rentsTable;
    private javax.swing.JPopupMenu rentsTablePopupMenu;
    private javax.swing.JMenuItem rentsTablePopupMenuDeleteItem;
    private javax.swing.JMenuItem rentsTablePopupMenuEditItem;
    private javax.swing.JMenuItem rentsTablePopupMenuReturnNowMenuItem;
    private javax.swing.JMenuItem rentsTablePopupMenuViewBookMenuItem;
    private javax.swing.JMenuItem rentsTablePopupMenuViewCustomerMenuItem;
    private javax.swing.JToolBar rentsToolBar;
    private javax.swing.JButton saveBookButton;
    private javax.swing.JButton saveCustomerButton;
    private javax.swing.JButton saveRentButton;
    private javax.swing.JTextField streetField;
    private javax.swing.JLabel streetLabel;
    private javax.swing.JTextField surnameField;
    private javax.swing.JLabel surnameLabel;
    private javax.swing.JTextField telephoneField;
    private javax.swing.JLabel telephoneLabel;
    private javax.swing.JTextField titleField;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables
}
